﻿using BLL;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace yuejilalala
{
    public partial class AddProduct : System.Web.UI.Page
    {
        ProductTypeMarager marager = new ProductTypeMarager();//商品类型Marager
        ProductMarager marager2 = new ProductMarager();//商品Marager
        StoreMarager marager3 = new StoreMarager();//商家Marager
        Product product = null;
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //初始显示所有商品类型
                DropDownList1.DataSource = marager.SumProductCount();
                DropDownList1.DataTextField = "TypeName";
                DropDownList1.DataValueField = "Id";
                DropDownList1.DataBind();
                //显示所有店铺(暂不是由店铺添加商品 而是由最终管理员添加)
                DropDownList2.DataSource = marager3.SumStore();
                DropDownList2.DataTextField = "storeName";
                DropDownList2.DataValueField = "Id";
                DropDownList2.DataBind();
            }
           
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            product = new Product();
            product.Proname = tb_name.Text;
            product.Protype = int.Parse(DropDownList1.SelectedValue);
            product.Proylcd = tb_ylcd.Text;
            product.Place = tb_cd.Text;
            product.Burd = tb_plb.Text;
            product.Speci = tb_cpgg.Text;
            product.Expir = tb_bzq.Text;
            product.Norm = tb_cpxkz.Text;
            product.Perms = tb_scxgz.Text;
            product.Way = tb_syfs.Text;
            product.Thumbnail = tb_slt.Text;
            product.Pic = tb_pic.Text + DropDownList3.SelectedValue;
            product.Price = decimal.Parse(tb_jg.Text);
            product.Stroe =int.Parse( DropDownList2.SelectedValue);
            if (marager2.AddProduct(product))
            {
                Response.Write("<script>alert('新增商品成功')</script>");
            }
        }
    }
}